package com.jmxcfc.blfsc.ninefour.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.jmxcfc.blfsc.common.sms.SmsConstants;
import com.jmxcfc.blfsc.common.common.request.BaseRequest;
import com.jmxcfc.blfsc.common.common.response.BaseResponse;
import com.jmxcfc.blfsc.common.exception.*;
import com.jmxcfc.blfsc.common.sms.BaseContext;
import com.jmxcfc.blfsc.common.sms.VoiceRequest;
import com.jmxcfc.blfsc.common.common.enums.ProcessStateEnum;
import com.jmxcfc.blfsc.common.sms.extend.VoiceExtend;
import com.jmxcfc.blfsc.common.sms.vo.FailListItem;
import com.jmxcfc.blfsc.common.validation.rule.RequestFieldRule;
import com.jmxcfc.blfsc.common.validation.rule.SmsRulesUtil;
import com.jmxcfc.blfsc.ninefour.common.Constants;
import com.jmxcfc.blfsc.ninefour.entity.SendDetailSub;
import com.jmxcfc.blfsc.ninefour.service.ISendDetailSubService;
import com.jmxcfc.blfsc.ninefour.service.IVoiceRequestService;
import com.jmxcfc.blfsc.ninefour.service.RequestApiService;
import com.jmxcfc.blfsc.ninefour.util.AESUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.*;

/**
 * <p>
 * 语音业务主表 服务实现类
 * 94语音的AI批量任务导入号码接口,接口文档地址
 https://94ai.yuque.com/staff-kqoz0c/xed39g/vifnf1?#GAyz6
 * </p>
 *
 * @author pbs
 * @since 2023-09-23 5:51:38
 */
@Slf4j
@Service
public class VoiceRequestServiceImpl implements IVoiceRequestService {

    //客户服务key
    @Value("${ninefour.appKey}")
    private String appKey;

    //秘钥由运营提供（企业信息中的appSecret）
    @Value("${ninefour.appSecret}")
    private String appSecret;
    /**
     * 发送失败策略
     * 0:表示导入验证成功的,返回失败的数据、1:表示全部数据（包括验证成功及失败的）都不导入
     */
    @Value("${ninefour.failReturn}")
    private Integer failReturn;



    @Value("${ninefour.importTaskCustomerUrl}")
    private String importTaskCustomerUrl;

    @Value("${ninefour.tokenUrl}")
    private String tokenUrl;


    private ISendDetailSubService sendDetailSubService;
    private RequestApiService requestApiService;
    private RestTemplate restTemplate;

    @Autowired
    public void setSendDetailSubService(ISendDetailSubService sendDetailSubService) {
        this.sendDetailSubService = sendDetailSubService;
    }

    @Autowired
    public void setRestTemplate(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

    @Autowired
    public void setRequestApiService(RequestApiService requestApiService) {
        this.requestApiService = requestApiService;
    }

  /*  @Override
    public JSONObject request(VoiceRequestMessage<JSONObject> voiceRequestMessage) {
        JSONObject requestJSONObject = JSON.parseObject(JSON.toJSONString(voiceRequestMessage));
        log.info("语音请求报文:{}",requestJSONObject);
        JSONObject resultJSONObject = new JSONObject();
        try {
            if(!CollectionUtils.isEmpty(voiceRequestMessage.getCustomers().stream().collect(Collectors.toList()))){
                LocalDateTime now = LocalDateTime.now();
                String dateTimeFormat = now.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));

                String dateTimeStr = String.valueOf(now.toInstant(ZoneOffset.ofHours(8)).toEpochMilli());
                String ciphertext = AesUtils.encrypt(appSecret, dateTimeFormat + "#" + appSecret);
                String iv = AESUtil.genTimestampIV(dateTimeStr);
                log.info("dateTimeFormat:{}",dateTimeFormat);
                log.info("dateTimeStr:{}",dateTimeStr);
                log.info("x-ciphertext:{}",ciphertext);
                log.info("iv:{}",iv);

                Map<String, String> headers = HttpClientUtil.createMap(
                        "x-access-token",getToken(dateTimeFormat),
                        "encrypt","AES/CBC/PKCS5PADDING",
                        "timestamp", dateTimeStr
                );

                //内容加密,发送语音请求,获取结果
                String content = AESUtil.cbcEncrypt(requestJSONObject.toString(), appSecret,  iv);
                log.info("content:{}",content);
                log.info("headers:{}",headers);
                ResponseEntity<String> responseEntity = client.post(importTaskCustomerUrl, content, headers,String.class);
                String responseEncrptData = client.responseDataToString(responseEntity);
                log.info("语音请求响应报密文为:{}",responseEncrptData);
                String jsonResult = AESUtil.cbcDecrypt(responseEncrptData, appSecret, AESUtil.genTimestampIV(String.valueOf(responseEntity.getHeaders().get("timestamp").get(0))));
                JSONObject result = JSON.parseObject(jsonResult);
                log.info("语音请求响应报明文为::{}",result);

                String rst = result.getInteger(Constants.CODE) == 200 ? ResultEnum.SUCCESS.getCode() : ResultEnum.FAIL.getCode();
                String msg = result.getInteger(Constants.CODE) == 200 ? ResultEnum.SUCCESS.getDescription() : ResultEnum.FAIL.getDescription();
                resultJSONObject.put(Constants.RESULT, rst);
                resultJSONObject.put(Constants.MESSAGE, msg);
                resultJSONObject.put("batchId", result.getString("batchId"));
                resultJSONObject.put("importNum", result.get("importNum"));
                resultJSONObject.put("data", result.get("data"));
            }else{
                resultJSONObject.put(Constants.RESULT, ResultEnum.EMPTY_DATALIST.getCode());
                resultJSONObject.put(Constants.MESSAGE, ResultEnum.EMPTY_DATALIST.getDescription());
            }
            log.info("94语音响应结果:{}",resultJSONObject);
            return resultJSONObject;
        } catch (Exception e) {
            log.error("94语音发送失败，原因:{}", e.getMessage());
            resultJSONObject.put("result",ResultEnum.EXP.getCode());
            resultJSONObject.put("message",ResultEnum.EXP.getDescription());
            log.info("94语音异常响应结果:{}",resultJSONObject);
            return resultJSONObject;
        }
    }
*/






    @Override
    public BaseResponse<JSONObject> sendRequest(BaseRequest<VoiceRequest<VoiceExtend>> requestMessage) {
        BaseContext<ResponseEntity<String>> baseContext = new BaseContext<>();
        //头部参数校验规则:业务号、请求流水号字段(94参数requestId)
        List<RequestFieldRule<?>> headerElementRules = baseContext.getHeaderElementRules();
        headerElementRules.add(SmsRulesUtil.getRequestNoRule());
        headerElementRules.add(SmsRulesUtil.getSerialSeqRule("批次号字段(94参数requestId)规则检验不符合"));
        //请求体参数校验:发送集合
        List<RequestFieldRule<?>> bodyElementRules = baseContext.getBodyElementRules();
        bodyElementRules.add(SmsRulesUtil.getSendDtlRule());
        bodyElementRules.add(SmsRulesUtil.getTaskIdlRule());
        return execute(requestMessage, baseContext);
    }


    @Override
    public <E> void validBodyExtend(VoiceRequest<VoiceExtend> body, BaseContext<E> baseHandleContext) throws ValidBodyException {
    }


    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public void beforeOutbound(BaseRequest<VoiceRequest<VoiceExtend>> request, BaseResponse<JSONObject> response, BaseContext<ResponseEntity<String>> baseContext) throws BeforeOutboundException {
        String requestNo = request.getHeader().getRequestNo();
        try {
            //
            String batchId = request.getHeader().getSerialSeq();
            log.info("语音请求业务号requestNo:{},requestId请求Id(批次号):{},94语音前置处理:数据落库和参数组装",requestNo,batchId);
            List<SendDetailSub> sendDetailSubList = new ArrayList<>();
            //左边为头部参数、右边为业务参数加密后的值
            Pair<Map<String, String>, String> requestParamPair = buildParam(request, sendDetailSubList);
            baseContext.setRestHttpEntity(creatRequestEntity(requestParamPair.getRight(),requestParamPair.getLeft()));
            //保存数据
            saveBatch(requestNo,sendDetailSubList);
            log.info("语音请求业务号requestNo:{},requestId请求Id(批次号):{},保存94语音明细表数据条数:{},前置处理结束", requestNo, batchId, sendDetailSubList.size());
        } catch (Exception e) {
            log.error("语音请求业务号requestNo:{},前置处理异常:{}", requestNo, e.getMessage(), e);
            throw new BeforeOutboundException(e.getMessage(), e);
        }
    }

    /**
     * 外呼操作
     * @param request
     * @param response
     * @param baseContext
     * @throws OutboundException
     */
    @Override
    public void outbound(BaseRequest<VoiceRequest<VoiceExtend>> request, BaseResponse<JSONObject> response, BaseContext<ResponseEntity<String>> baseContext) throws OutboundException {
        try {
            log.info("语音请求业务号requestNo:{},请求外呼,请求地址:{},请参数:{}",request.getHeader().getRequestNo(),importTaskCustomerUrl,baseContext.getRestHttpEntity());
            ResponseEntity<String>  responseEntity= restTemplate.postForEntity(importTaskCustomerUrl, baseContext.getRestHttpEntity(), String.class);
            log.info("语音请求业务号requestNo:{},请求外呼,响应内容:{}", request.getHeader().getRequestNo(), responseEntity);
            baseContext.setRestResponse(responseEntity);
        } catch (Exception e) {
            log.error("语音请求业务号requestNo:{},请求外呼异常:{}", request.getHeader().getRequestNo(), e.getMessage(),e);
            throw new OutboundException(e.getMessage(), e);
        }
    }


    /**
     * 响应内容解析
     *1、 状态判断看 code字段:
     100	失败，签名校验不通过
     200	数据推送成功
     300	失败，参数异常，xxx
     500	失败，服务器异常，请稍后重试
     700	失败，数据超过最大值
     1001	失败，合作方不存在
     1002	失败，外呼任务不存在
     1003	失败，用户信息参数不符合外呼任务参数要求
     2003	失败，号码重复当前外呼号码导入存在导入重复。

     * 2、failReturn=0和failReturn=1响应的结果不一致
     failReturn=0时,导入验证成功失败,返回验证失败的数据在data字段【code=200】
     failReturn=1时,不返回data字段,整个批次:表示全部数据(包括验证成功及失败的)都不导入
     code=200 代表全部导入成功
     code!=200,导入失败,message会响应错误信息
     * 3、存在直接响应明文的场景
     当token 不正确时,则data直接响应的是明文,案例
     {"code":401,"message":"未授权"}
     * @param request
     * @param response
     * @param baseContext
     * @throws AfterOutboundException
     */
    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public void afterOutbound(BaseRequest<VoiceRequest<VoiceExtend>> request, BaseResponse<JSONObject> response, BaseContext<ResponseEntity<String>> baseContext) throws AfterOutboundException {
        String requestNo = request.getHeader().getRequestNo();
        String serialSeq = request.getHeader().getSerialSeq();
        try {
            ResponseEntity<String> responseEntity = baseContext.getRestResponse();
            String body = responseEntity.getBody();
            log.info("语音请求业务号requestNo:{},后置处理:解析响应结果:{}", requestNo,body);
            //响应blfs-sms模块的扩展字段
            JSONObject responseBody = new JSONObject();
            //解密
            String responseDataStr = AESUtil.cbcDecrypt(body, appSecret, AESUtil.genTimestampIV(String.valueOf(responseEntity.getHeaders().get("timestamp").get(0))));
            JSONObject responseData = JSON.parseObject(responseDataStr);
            String code ;
            String message;
            String respBatchId = "";
            ArrayList<JSONObject > responseFailDataList = new ArrayList<>();
            if (Objects.isNull(responseDataStr)||Objects.isNull(responseData)){
                log.error("语音请求业务号requestNo:{},94语音响应body:{},进行解密为空,则对data直接进行处理【对方直接响应明文】", requestNo, body);
                JSONObject bodyOb = Optional.ofNullable(JSON.parseObject(body)).orElse(new JSONObject());
                code = bodyOb.getString(Constants.RESP_CODE);
                message = bodyOb.getString(Constants.RESP_MESSAGE);
                response.getHeader().setProcessState(ProcessStateEnum.FAILURE);
            }else {
                log.info("语音请求业务号requestNo:{},requestId请求Id(批次号):{},语音请求响应,解析成明文为{}", requestNo, serialSeq, responseData);
                code = responseData.getString(Constants.RESP_CODE);
                message = responseData.getString(Constants.RESP_MESSAGE);
                respBatchId = responseData.getString(Constants.RESP_BATCH_ID);
                responseFailDataList = JSON.parseObject(responseData.getString(Constants.RESP_DATA), new TypeReference<ArrayList<JSONObject>>() {
                });
                if (StringUtils.equals(Constants.STRING_200, code)&&CollectionUtils.isEmpty(responseFailDataList)) {
                    response.getHeader().setProcessState(ProcessStateEnum.NOTIFICATION);
                }else {
                    response.getHeader().setProcessState(ProcessStateEnum.FAILURE);
                }
            }
            //更新数据规则:当(失败数据为空)或者(存在部分失败数据和发送的数据数量不等时),则更新全部数据
            if (CollectionUtils.isEmpty(responseFailDataList)||request.getBody().getSendDtl().size()!=responseFailDataList.size()) {
                updateSendDetailSub(requestNo,serialSeq, code, message, respBatchId);
            }

            //存在部分失败数据时，则在把失败数据更新
            if (CollectionUtils.isNotEmpty(responseFailDataList)) {
                log.warn("语音请求业务号requestNo:{},94语音响应,存在全部或者部分失败号码,data:{}",requestNo,responseFailDataList);
                List<FailListItem> failListItemList = new ArrayList<>(responseFailDataList.size());
                List<SendDetailSub> updateSendDetailSubList = new ArrayList<>(responseFailDataList.size());
                for (JSONObject failJSONObject:responseFailDataList) {
                    SendDetailSub sendDetailSub = new SendDetailSub();
                    sendDetailSub.setUuid(failJSONObject.getString(Constants.TAG));
                    sendDetailSub.setCode(code);
                    sendDetailSub.setMessage(message);
                    sendDetailSub.setData(failJSONObject.toJSONString());
                    sendDetailSub.setBatchId(respBatchId);
                    updateSendDetailSubList.add(sendDetailSub);
                    FailListItem failListItem = new FailListItem();
                    failListItem.setUuid(failJSONObject.getString(Constants.TAG));
                    failListItem.setErrorCode(code);
                    failListItem.setErrorDesc(failJSONObject.toJSONString());
                    failListItemList.add(failListItem);
                }
                message = StringUtils.joinWith(Constants.AND, message, "存在全部或部分失败");
                //失败列表数据
                responseBody.put(SmsConstants.RESP_FAIL_LIST, failListItemList);
                Optional.ofNullable(CollectionUtils.isEmpty(updateSendDetailSubList)?null:updateSendDetailSubList).ifPresent(
                        sendDetailSubs ->{
                            log.warn("语音请求业务号requestNo:{},更新NF_SEND_DETAIL_SUB 表,记录导入失败的号码",requestNo);
                            sendDetailSubService.updateBatchById(sendDetailSubs);
                        }
                );
            }
            response.getHeader().setResCode(code);
            response.getHeader().setResMessage(message);
            response.setBody(responseBody);
            //response.setErrorCode(code);
            //response.setErrorDesc(message);
            //response.setExtend(responseBody);
            //response.setEndTime(LocalDateTime.now());
        } catch (Exception e) {
            log.error("语音请求业务号requestNo:{},后置处理异常:{}", requestNo, e.getMessage(), e);
            throw new AfterOutboundException(e.getMessage(), e);
        }
    }



    

    /**
     * 数据保存
     * @param requestNo
     * @param sendDetailSubList
     */
    private void saveBatch(String requestNo,List<SendDetailSub> sendDetailSubList) {
        try {
            sendDetailSubService.saveBatch(sendDetailSubList);
        } catch (DuplicateKeyException e) {
            log.error("语音请求业务号requestNo:{},保存94语音明细数据,存在重复主键Id,违反唯一约束条件", requestNo);
            throw new RepetitionException(e);
        }
    }




    /**
     * 参数组织
     *
     * request.getHeader().getSerialSeq()=>requestId
     * 1、业务参数加密方式:
      加密方式AES/CBC/PKCS5PADDING,密钥为appSecret,IV为单次请求时间戳（时间戳为13位毫秒数）反转，用0补满16位字符串，
      加密内容为post请求内容体
     * 2、头部需要获取accessToken:
     调⽤接⼝http[s]://[gateway-endpoint]/authority/accessToken?cropId={cropId}
     请求⽅式为GET 需要包含以下
     header:
     x-timestamp: 当前时间戳,格式为: yyyyMMddHHmmss
     x-ciphertext: 密⽂,密⽂为Aes算法加密串,aesKey为: {x-timestamp}+'#'+{secret}. 加密算法为Aes({secret}, {aseKey})
     *  @param request
     * @param sendDetailSubList
     * @return: 左边返回:头部参数、右边返回:请求体里加密的数据
     */
    private Pair<Map<String, String>,String> buildParam(BaseRequest<VoiceRequest<VoiceExtend>> request, List<SendDetailSub> sendDetailSubList) throws Exception {
        String requestNo = request.getHeader().getRequestNo();
        //对应94语音的requestId字段
        String serialSeq = request.getHeader().getSerialSeq();

        if (CollectionUtils.isEmpty(request.getBody().getSendDtl())){
            log.error("语音请求业务号requestNo:{},requestId请求ID(批次号):{},请求参数的发送集合是空", requestNo, serialSeq);
            throw new BeforeOutboundException("语音发送集合sendDtl字段为空!");
        }
        JSONObject requestParam = new JSONObject();
        requestParam.put(Constants.REQUEST_ID, serialSeq);

        Integer failReturnParam = StringUtils.isBlank(request.getBody().getExtend().getFailReturn())?failReturn:Integer.parseInt(request.getBody().getExtend().getFailReturn());
        //接口数据类型:Integer:0:表示导入验证成功的,返回失败的数据、1:表示全部数据（包括验证成功及失败的）都不导入
        requestParam.put(Constants.FAIL_RETURN, failReturnParam);
        //接口数据类型:Integer
        requestParam.put(Constants.TASK_ID, Integer.parseInt(request.getBody().getTaskId()));
        List<JSONObject> customers = new ArrayList<>();
        request.getBody().getSendDtl().forEach(voiceParamItem -> {
            JSONObject customersItem = new JSONObject();
            customersItem.put(Constants.NUMBER, voiceParamItem.getCellPhoneNo());
            //用户自定义标签字段
            customersItem.put(Constants.TAG, voiceParamItem.getUuid());
            // //用户具体信息,需根据具体任务参数要求传输(JSON串,接口请求参数)
            customersItem.put(Constants.PROPERTIES, voiceParamItem.getProperties());
            customers.add(customersItem);

            SendDetailSub sendDetailSub = new SendDetailSub();
            //流水号,可以标识一个批次下的具体一条语音
            sendDetailSub.setUuid(voiceParamItem.getUuid());
            //请求业务号(上游传值)
            sendDetailSub.setRequestNo(requestNo);
            //请求号(批次号),blfs-sms生成
            sendDetailSub.setRequestId(serialSeq);
            //手机号
            sendDetailSub.setCellPhoneNo(voiceParamItem.getCellPhoneNo());
            //任务id
            sendDetailSub.setTaskId(Integer.parseInt(request.getBody().getTaskId()));
            //返回类型
            sendDetailSub.setFailReturn(String.valueOf(failReturnParam));
            sendDetailSub.setProperties(JSON.toJSONString(voiceParamItem.getProperties()));
            sendDetailSubList.add(sendDetailSub);
        });
        //外呼客户
        requestParam.put(Constants.CUSTOMERS, customers);
        log.info("语音请求业务号requestNo:{},请求号requestId(批次号):{},加密前的业务参数:{}", requestNo, serialSeq, JSON.toJSONString(requestParam));
        /**
         * 加密方式AES/CBC/PKCS5PADDING,密钥为appSecret,IV为单次请求时间戳（时间戳为13位毫秒数）反转，用0补满16位字符串，
         * 加密内容为post请求内容体
         */
        //内容加密:
        LocalDateTime now = LocalDateTime.now();
        String dateTimeStr = String.valueOf(now.toInstant(ZoneOffset.ofHours(8)).toEpochMilli());
        //根据时间戳13位，生成aes cbc 加密向量 vi
        String iv = AESUtil.genTimestampIV(dateTimeStr);
        //加密后的内容
        String content = AESUtil.cbcEncrypt(requestParam.toString(), appSecret,  iv);
        String timestamp = now.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
        //头部参数组织
        Map<String, String> headers = new HashMap<>();
        headers.put("x-access-token", requestApiService.getToken(requestNo, appKey, appSecret, timestamp));
        headers.put("encrypt", Constants.ENCRYPT);
        headers.put("timestamp", dateTimeStr);
        log.info("语音请求业务号requestNo:{},参数组织完成,headers:{},加密后的content内容:{}", requestNo, headers, content);
        return Pair.of(headers, content);
    }

    /**
     * 解析94语音响应,更新94语音明细表【data字段是空的场景更新逻辑,说明没有响应失败的号码明细】
     * @param requestNo:业务号
     * @param serialSeq:请求流水号,对应94语音的是 requestId
     * @param code
     * @param message
     * @param respBatchId
     */
    private void updateSendDetailSub(String requestNo,String serialSeq, String code,String message,String respBatchId){
        UpdateWrapper<SendDetailSub> updateWrapper = new UpdateWrapper<>();
        updateWrapper.lambda().set(SendDetailSub::getCode, code)
                .set(SendDetailSub::getMessage, message)
                //响应字段: batchId字段:导入号码时返回的批次号
                .set(StringUtils.isNotBlank(respBatchId),SendDetailSub::getBatchId,respBatchId)
                .eq(SendDetailSub::getRequestNo, requestNo)
                //在blfs-sms模块生成的:请求id，具有唯一性(批次ID)、标识每一个批次
                .eq(SendDetailSub::getRequestId, serialSeq);
        sendDetailSubService.update(new SendDetailSub(), updateWrapper);
        log.info("语音请求业务号requestNo:{},94语音响应code字段:{},根据requestNo、requestId,更新94语音明细表数据",requestNo, code);
    }

    /**
     * 创建请求的HttpEntity
     * @param params
     * @param headers
     * @return
     */
    public HttpEntity<String> creatRequestEntity(String params,Map<String, String> headers) {
        HttpHeaders requestHeaders = new HttpHeaders();
        requestHeaders.setContentType(MediaType.parseMediaType(Constants.MEDIA_TYPE_APPLICATION_JSON_UTF8));
        requestHeaders.setAll(headers);
        return new HttpEntity<>(params, requestHeaders);

    }
    /**
     * 获取94语音公共token
     * @param dateTimeFormat
     * @return
     * @throws Exception
     */
   /* public String getToken(String dateTimeFormat) throws Exception {
        log.info("getToken start");
        Map<String, String> headers = new HashMap<>();
        headers.put("x-timestamp",dateTimeFormat);
        headers.put("x-ciphertext",AesUtils.encrypt(appSecret,dateTimeFormat+"#"+appSecret));
        Map<String, Object> uriVariables = new HashMap<>();
        uriVariables.put("cropId",appKey);
        ResponseEntity<JSONObject> responseEntity = client.get(tokenUrl, null, headers, JSONObject.class, uriVariables);
        String token = client.responseTokenDataToString(responseEntity);
        log.info("getToken end, token:{}",token);
        return token;
    }*/






    
}
